package com.puboot.common.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author Leonidax
 * @date 2024/10/24 09:34
 * @description ComicService
 */
@Repository
public class ComicService implements ComicDao{
    private final JdbcTemplate jdbcTemplate;
    @Autowired
    public ComicService(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    @Override
    public List<Map<String, Object>> findAllTest0() {
        String sql = "select id, comic_py from lk_comic";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> findAllChapters() {
        String sql = "select chapter_id,comic_id from lk_comic_chapter";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> findAllCates() {
        String sql = "select id,cate from lk_comic";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public List<Map<String, Object>> findAllBaseCates() {
        String sql = "select title,to_id from base_cate";
        return jdbcTemplate.queryForList(sql);
    }

    @Override
    public int insertCate2Comic(Integer comicId, Integer cateId) {
        String sql = "INSERT INTO r_cate_comic (comic_id, cate_id) VALUES (?,?)";
        return jdbcTemplate.update(sql, comicId, cateId);
    }

    @Override
    public int insertCate(String cate) {
        String sql = "INSERT INTO lk_cate (lang) VALUES (?)";
        return jdbcTemplate.update(sql, cate);
    }

    @Override
    public int insertChapter(Integer comicId, Integer chapterId, String title, String content) {
        String sql = "INSERT INTO lk_comic_chapter (comic_id, chapter_id, title, content) VALUES (?,?,?,?)";
        return jdbcTemplate.update(sql, comicId, chapterId, title, content);
    }

    @Override
    public int insertComic(Integer id, String title, String author, String cate, String cover, Integer hits, String intro, String comicPy) {
        String sql = "INSERT INTO lk_comic (id, title, author,cate,cover,hits,intro,comic_py) VALUES (?,?,?,?,?,?,?,?)";
        return jdbcTemplate.update(sql, id, title, author,cate,cover,hits,intro,comicPy);
    }
}
